<template>
  <div id="topSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <el-form-item label="标签状态" prop="status">
          <el-select v-model="formInline.status">
            <el-option
              v-for="item in statusList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="删除状态" prop="deleted">
          <el-select v-model="formInline.deleted">
            <el-option
              v-for="item in deleteList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="子频道名称" prop="tagName">
          <el-input
            v-model="formInline.tagName"
            placeholder="请输入子频道名称进行搜索"
          ></el-input>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  name: 'TopSearch',
  msg: '角色管理-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          status: '',
          deleted: '',
          tagName: ''
        }
      }
    }
  },
  data() {
    return {
      statusList: [{ dictLabel: '全部', dictValue: '' }],
      deleteList: [],
      rules: {
        status: {},
        deleted: {},
        tagName: {}
      }
    }
  },
  mounted() {
    this.getStickList()
  },
  methods: {
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
      //设置默认数据
      this.setDefaultValue()
    },
    /* 获取数据状态 */
    async getStickList() {
      // 内容标签开启状态
      let tagStatus = await sysNormalDisable(
        'content_tag_open_status',
        'tagStatus'
      )
      this.statusList = this.statusList.concat(tagStatus)
      // 内容标签删除状态
      this.deleteList = await sysNormalDisable('content_tag_status')
      this.setDefaultValue()
      //触发列表获取权限
      this.$emit('toSearch')
    },
    /*设置默认数据*/
    setDefaultValue() {
      this.formInline.deleted = this.deleteList[0].dictValue
      this.formInline.status = this.statusList[0].dictValue
    }
  }
}
</script>

<style lang="less">
#topSearch {
  .search-box {
    padding-left: 30px !important;
  }
}
</style>
